{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# SAKSHAT提供的LED使用方法\n",
    "当前SAKSHAT为我们提供的方法参考：http://wiki.nxez.com/saks:sdk:libraries:led74hc595\n",
    "\n",
    "这里就直接摘录了，以下是创百科的内容:\n",
    "\n",
    "74HC595 芯片驱动下的 LED 灯组类，控制一组 LED 工作。\n",
    "方法\n",
    "\n",
    "__init__(self, pins, real_true = GPIO.HIGH)\n",
    "\n",
    "初始化对象，设置引脚和触发电平（高电平或低电平触发）。pins 为 IO 引脚数组。\n",
    "\n",
    "ic(self)\n",
    "\n",
    "返回当前驱动数码管的IC对象。\n",
    "\n",
    "is_on(self, index)\n",
    "\n",
    "返回当前 LED 的工作状态。true 或 false。index 为 LED 编号，从 0 开始。\n",
    "\n",
    "row_status(self)\n",
    "\n",
    "返回当前 LED 灯组的工作状态的数组。\n",
    "\n",
    "on(self)\n",
    "\n",
    "设置 LED 灯组为全部点亮状态。\n",
    "\n",
    "off(self)\n",
    "\n",
    "设置 LED 灯组为全部熄灭状态。\n",
    "\n",
    "on_for_index(self, index)\n",
    "\n",
    "设置当前 LED 灯组的第 index+1 个 LED 的状态为点亮。index 为 LED 编号，从 0 开始。\n",
    "\n",
    "off_for_index(self, index)\n",
    "\n",
    "设置当前 LED 灯组的第 index+1 个 LED 的状态为熄灭。index 为 LED 编号，从 0 开始。\n",
    "\n",
    "set_row(self, status)\n",
    "\n",
    "设置当前 LED 灯组的点亮状态。status 为布尔型数组。status 中的元素也可以为 None，表示不改变该元素位置的 LED 状态。 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#点亮所有LED灯\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #点亮所有LED灯\n",
    "        SAKS.ledrow.on()\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#熄灭所有LED灯\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #熄灭所有LED灯\n",
    "        SAKS.ledrow.off()\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#返回当前LED灯组状态。\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "led_status = []\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #点亮所有灯并输出所有灯状态\n",
    "        for i in range(0, 8):\n",
    "            SAKS.ledrow.on_for_index(i)\n",
    "        led_status = SAKS.ledrow.row_status\n",
    "        print(\"点亮所有灯状态\" + str(led_status))\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "        #关闭所有灯并输出等状态\n",
    "        for i in range(0, 8):\n",
    "            SAKS.ledrow.off_for_index(i)\n",
    "        led_status = SAKS.ledrow.row_status\n",
    "        print(\"关闭所有灯状态\" + str(led_status))\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "        #熄灭所有LED灯\n",
    "        SAKS.ledrow.off()\n",
    "        \n",
    "        #间隔点亮LED灯模式１\n",
    "        for i in range(0, 8, 2):\n",
    "            SAKS.ledrow.on_for_index(i)\n",
    "        led_status = SAKS.ledrow.row_status\n",
    "        print(\"间隔点亮LED灯模式１\" + str(led_status))\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "        #熄灭所有LED灯\n",
    "        SAKS.ledrow.off()\n",
    "        \n",
    "        #间隔点亮LED灯模式2\n",
    "        for i in range(1, 8, 2):\n",
    "            SAKS.ledrow.on_for_index(i)\n",
    "        led_status = SAKS.ledrow.row_status\n",
    "        print(\"间隔点亮LED灯模式2\" + str(led_status))\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#返回当前LED单个灯状态。\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "led_status = []\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #熄灭所有LED灯\n",
    "        SAKS.ledrow.off()\n",
    "        \n",
    "        #关闭所有灯并输出等状态\n",
    "        for i in range(0, 8, 2):\n",
    "            SAKS.ledrow.on_for_index(i)\n",
    "        led_status = SAKS.ledrow.row_status\n",
    "        print(\"关闭所有灯状态\" + str(led_status))\n",
    "        \n",
    "        for i in range(0, 8):\n",
    "            led_one_status = SAKS.ledrow.is_on(i)\n",
    "            print(\"第\" + str(i) + \"个LED灯状态为\" + str(led_one_status))\n",
    "              \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#逐一点亮LED灯，然后逐一熄灭LED灯\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        for i in range(0, 8):\n",
    "            SAKS.ledrow.on_for_index(i)\n",
    "            time.sleep(1)\n",
    "            \n",
    "        for i in range(0, 8):\n",
    "            SAKS.ledrow.off_for_index(i)\n",
    "            time.sleep(1)\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#设置LED灯族状态\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        SAKS.ledrow.set_row([True, False, True, False, True, False, True, False])\n",
    "\n",
    "        time.sleep(5)\n",
    "\n",
    "        SAKS.ledrow.set_row([None, True, None, True, None, None, None, None])\n",
    "\n",
    "        time.sleep(5)\n",
    "        \n",
    "        SAKS.ledrow.set_row([None, None, None, None, None, True, None, True])\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "        SAKS.ledrow.set_row([False, None, False, None, False, None, False, None])\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "        SAKS.ledrow.set_row([False, False, False, False, False, False, False, False])\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#流水灯走起\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        while True:         \n",
    "            for i in range(0, 8):\n",
    "                SAKS.ledrow.on_for_index(i)\n",
    "                time.sleep(0.1)\n",
    "                SAKS.ledrow.off_for_index(i)\n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
